﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;

namespace CafeOnline.MvcFramework.Web.Json {
    public class JavascriptFunction : JRaw{

        /// <summary>
        /// Creates a new Javascript function.
        /// </summary>
        /// <param name="value">name of the function to call.</param>
        public JavascriptFunction(string value)
            : base(value) {
        }

        /// <summary>
        /// Creates a new Javascript function based on a format string and the arguments.
        /// </summary>
        /// <remarks>
        /// It is important to double quote required { and }: so { becomes {{  and } becomes
        /// }}.
        /// </remarks>
        /// <param name="valueFormat">The value format.</param>
        /// <param name="args">The formatting arguments.</param>
        public JavascriptFunction(string valueFormat, params object[] args)
            : base(string.Format(valueFormat, args)) {
        }

        /// <summary>
        /// Performs an implicit conversion from <see cref="System.String"/> to <see cref="Cvs.Checker.Website.Framework.Web.Json.JavascriptFunction"/>.
        /// </summary>
        /// <param name="s">the string to convert</param>
        /// <returns>
        /// Javascript function converted.
        /// </returns>
        public static implicit operator JavascriptFunction(string s) {
            return new JavascriptFunction(s);
        }
    }
}
